/**
 * Created by dukes on 2015/10/27.
 */
class DecorateScene extends eui.Component{
    constructor(){
        super();
        this.skinName = "pet.DecorateScemeSkin";
        this.name = "decscene";
        this.addEventListener(egret.Event.ADDED_TO_STAGE,this.addedToStage, this );
        this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.removedFromStage, this);
        this.frameItem = new FrameItem();
        this.frameItem.callObj = this;
        this.frameItem.callFun = this.update;
    }
    private update(delta:number){
        if( !this.curDec) return;
        if( !this.curDec.isPernant){
            var timeRest = this.curDec.expireTime - Model.SYSTIME;
            if( timeRest > 0){
                if( timeRest > Model.DAY){
                    this.lab_desc_2.text = "时效:剩余"+Math.round(timeRest/Model.DAY)+"天";
                }else{
                    this.lab_desc_2.text = "时效:"+GetTimeStr(timeRest);
                }
            }else{
                this.lab_desc_2.text = "00:00:00";
                FrameMgr.getInstance().delController(this.name);
            }

        }else{
            this.lab_desc_2.text = "时效:永久";
            FrameMgr.getInstance().delController(this.name);
        }
    }
    private frameItem:FrameItem;
    private decorates:number[];
    private curIndex:number = 0;
    private curItems:GoodInfo[];
    private curShowType:number;
    //4 ���� 5 �� 6 ��� 7 ��� 8ͷ�� 9�۲� 10 ����
    private indexMap = {4:0,5:0,6:0,7:0,8:0,9:0,10:0};
    public showType(type:number){
        if( this.curShowType == type) return;
        this.curShowType = type;
        this.curIndex = this.indexMap[type];
        this.curItems = [];
        var len = this.goodList.length;
        var goodId;
        var good:GoodInfo;
        for(var i = 0; i < len; i++){
            goodId = this.goodList[i];
            good = Model.GetDecorateById(goodId);
            if( good.classify == type){
                this.curItems.push(good);
            }
        }
        this.curItems.sort(this.compare);
        this.updateDisplay();
    }
    private compare(item0, item1):number{
        if( item0.orders != item1.orders)
            return item0.orders < item1.orders ? 1 : -1;
        else
            return item0.id > item1.id ? 1 : -1;
    }
    public checkSavable(){
        if( this.tempDressData.length){
            RemindPanel.getInstance().showContent("是否保存当前装扮？",this,this.onSave,this.onCancel);
        }
    }
    private onCancel(){
        this.tempDressData = [];
    }
    private goodList:number[];
    private curPet:Pet;
    public pageHandler(){
        if( this.tempDressData.length){
            RemindPanel.getInstance().showContent("是否保存当前装扮？",this,this.onSave,this.updatePetPage);
        }else{
            this.updatePetPage();
        }
    }
    private updatePetPage(){
        this.curPet = PetMgr.getInstance().curPet;
        this.curPetDecorates = Model.currentDecorators|| [];
        this.tempDressData = [];
        this.img_cur_mark.x = this.img_decorate.x + 17;
        this.img_cur_mark.y = this.img_decorate.y + 55;
        this.indexMap = {4:0,5:0,6:0,7:0,8:0,9:0,10:0};
        if(this.curPet.type == Model.GOOD_TYPE_CAT){
            this.goodList = Model.decorators4cat;
        }else{
            this.goodList = Model.decorators4dog;
        }
        if( !Model.petAttributes){
            window["__iwars"](PetMgr.getInstance().curPet.petId);
        }else{
            PlayBar.getInstance().updateDecorateRelated();
        }
        this.showType(Model.DEC_BG);;
        this.updateItems();
        this.updateDisplay();
        this.updateButtons();
    }
    private curGood:GoodInfo;
    private curPetDecorates:DecorateInfo[];
    private tempDressData:number[];//临时穿戴数据
    //private takeOffData:number[];
    private updateDisplay(){
        this.img_left.visible = this.curIndex != 0;
        this.img_right.visible = this.curIndex < this.curItems.length-1;
        this.curGood = this.curItems[this.curIndex];
        this.updateButtons();

        this.img_icon.source = GameConst.Res_Root+"resource/assets/decorates/"+this.curGood.id+(this.curShowType != 4 ? ".png" :"-1.jpg");
        this.lab_good_name.text = this.curGood.name;
        var num;
        var url;
        var decInfo = Model.GetDecDateById(this.curGood.id);
        if( decInfo && decInfo.descs && decInfo.descs.length != 0){
            this.lab_dec_desc.visible = true;
            this.lab_dec_desc.text = decInfo.descs;
            this.group_price.visible = this.img_money.visible = false;
            this.img_buy.visible = false;
        }else{
            if( this.curGood.byDiamond){
                num = this.curGood.price;
                url = "img_diamond";
            }else if(this.curGood.bySproutPoint){
                num = this.curGood.disPrice;
                url = "meng_point";
            }else{
                num = this.curGood.hair;
                if( this.curGood.byCatHair && Model.me.myType == Model.GOOD_TYPE_CAT){
                    url = "img_money_cat" ;
                }else if( this.curGood.byDogHair && Model.me.myType == Model.GOOD_TYPE_DOG){
                    url = "img_money_dog";
                }else{
                    url = this.curGood.byCatHair ? "img_money_cat" : "img_money_dog";
                }
            }
            this.group_price.text = num+"";
            this.img_money.source = url;
            this.lab_dec_desc.visible = false;
            this.group_price.visible = this.img_money.visible = true;
        }

        this.lab_desc_1.text = this.curGood.descs;
        if( !this.curDec){
            var unlockConfig = Model.GetDecUnlockConfig(this.curGood.id);
            if( unlockConfig && Model.me.vipLevel < unlockConfig.count){
                this.lab_desc_2.text = "VIP"+unlockConfig.count+"解锁";
            }else{
                if(this.curGood.term != 0){
                    var timeLast = this.curGood.term*60*1000;
                    if( timeLast > Model.DAY){
                        this.lab_desc_2.text = "时效:"+Math.round(timeLast/Model.DAY)+"天";
                    }else{
                        this.lab_desc_2.text = "时效:"+GetTimeStr(timeLast);
                    }
                }else{
                    this.lab_desc_2.text = "时效:永久";
                }
            }
        }
    }
    private curDec;
    private updateButtons(){
        var petId = PetMgr.getInstance().curPet.petId;
        var curDec = Model.DecorateOn(this.curGood.id);
        var HasFreeDec = Model.HasFreeDec(this.curGood.id);
        this.img_using.visible = curDec != null;
        this.img_using_icon.visible = curDec != null && curDec.petId != petId;
        if( curDec){
            this.img_using_icon.source = GameConst.Res_Root+"resource/assets/petpreview/"+curDec.petId+".png";

        }
        this.curDec = curDec || HasFreeDec;
        if( this.curDec ){
            if( !FrameMgr.getInstance().isUnderControl(this.name)){
                FrameMgr.getInstance().addControll(this.frameItem);
            }
        }else{
            if( FrameMgr.getInstance().isUnderControl(this.name)){
                FrameMgr.getInstance().delController(this.name);
            }
        }
        this.img_dressup.visible = HasFreeDec && !curDec;
        this.img_buy.visible = !HasFreeDec && !curDec && this.curGood.canBuy;
        this.img_try.visible = !HasFreeDec && !curDec && this.tempDressData.indexOf(this.curGood.id) == -1 && this.limitTryData.indexOf(this.curGood.id) == -1;
        this.img_takeoff.visible = (curDec != null && petId == curDec.petId)  ||
            (this.curGood.canBuy && this.tempDressData.indexOf(this.curGood.id) != -1) ||
            (!this.curGood.canBuy && this.limitTryData.indexOf(this.curGood.id) != -1) ;
        this.img_save.visible = this.img_reset.visible = this.tempDressData.length != 0;
    }

    public takeoffAll(){
        var type = this.getOriginal();
        var classify = this.curGood.classify;
        if( classify == Model.DEC_BG){
            PetMgr.getInstance().changeBg(type);
        }else if( classify == Model.DEC_NEST){
            this.img_nest.visible = type != 0;
            if( type != 0)
                this.img_nest.source = GameConst.Res_Root+"resource/assets/decorates/"+type+ ".png";
        }else if( classify == Model.DEC_TOY){
            this.img_doll.visible = type != 0;
            if( type != 0)
                this.img_doll.source = GameConst.Res_Root+"resource/assets/decorates/"+type+ ".png";
        }else if( classify == Model.DEC_FRAME){
            this.img_frame.visible = type != 0;
            if( type != 0)
                this.img_frame.source = GameConst.Res_Root+"resource/assets/decorates/"+type+ ".png";
        }else if( classify == Model.DEC_HAT){
            if( type != 0)
                RES.getResByUrl(GameConst.Res_Root+"resource/assets/decorates/"+type+ ".png",this.onHatComplete,this);
            else
                AnimationController.getInstance().setSlotDisplay("mypet","tou",false);
        }else if( classify == Model.DEC_GLASS){
            if( type != 0)
                RES.getResByUrl(GameConst.Res_Root+"resource/assets/decorates/"+type+ ".png",this.onGlassComplete,this);
            else
                AnimationController.getInstance().setSlotDisplay("mypet","yanjing",false);
        }else if( classify == Model.DEC_NECKLACE){
            if( type != 0)
                RES.getResByUrl(GameConst.Res_Root+"resource/assets/decorates/"+type+ ".png",this.onNeckComplete,this);
            else
                AnimationController.getInstance().setSlotDisplay("mypet","bozi",false);
        }
    }
    private limitTryData = [];
    public doDress(){
        if( this.curGood.canBuy || Model.HasFreeDec(this.curGood.id)){
            if( this.tempDressData.length == 0){
                this.tempDressData.push(this.curGood.id);
            }else{
                var idx = this.getIndex();
                if( idx == -1){
                    this.tempDressData.push(this.curGood.id);
                }else{
                    this.tempDressData[idx]=this.curGood.id;
                }
            }
            idx = this.getAnotherIndex();
            if( idx != -1){
                this.limitTryData.splice(idx,1);
            }
        }else if( !this.curGood.canBuy){
            idx = this.getAnotherIndex();
            if( idx == -1){
                this.limitTryData.push(this.curGood.id);
            }else{
                this.limitTryData[idx] = this.curGood.id;
            }
            idx = this.getIndex();
            if( idx != -1){
                this.tempDressData.splice(idx,1);
            }
        }

        //4 bg 5 nest 6 toy 7 frame 8 hat 9 glass 10 necklace
        if( this.curGood.classify == Model.DEC_BG){
            PetMgr.getInstance().changeBg(this.curGood.id);
        }else if( this.curGood.classify == Model.DEC_NEST){
            this.img_nest.visible = true;
            this.img_nest.source = GameConst.Res_Root+"resource/assets/decorates/"+this.curGood.id+ ".png";
        }else if( this.curGood.classify == Model.DEC_TOY){
            this.img_doll.visible = true;
            this.img_doll.source = GameConst.Res_Root+"resource/assets/decorates/"+this.curGood.id+ ".png";
        }else if( this.curGood.classify == Model.DEC_FRAME){
            this.img_frame.visible = true;
            this.img_frame.source = GameConst.Res_Root+"resource/assets/decorates/"+this.curGood.id+ ".png";
        }else if( this.curGood.classify == Model.DEC_HAT){
            RES.getResByUrl(GameConst.Res_Root+"resource/assets/decorates/"+this.curGood.id+ ".png",this.onHatComplete,this);
        }else if( this.curGood.classify == Model.DEC_GLASS){
            RES.getResByUrl(GameConst.Res_Root+"resource/assets/decorates/"+this.curGood.id+ ".png",this.onGlassComplete,this);
        }else if( this.curGood.classify == Model.DEC_NECKLACE){
            RES.getResByUrl(GameConst.Res_Root+"resource/assets/decorates/"+this.curGood.id+ ".png",this.onNeckComplete,this);
        }
    }
    private onHatComplete(hehe){
        AnimationController.getInstance().setSlotDisplay("mypet","tou",true,hehe);
    }
    private onGlassComplete(hehe){
        AnimationController.getInstance().setSlotDisplay("mypet","yanjing",true,hehe);
    }
    private onNeckComplete(hehe){
        AnimationController.getInstance().setSlotDisplay("mypet","bozi",true,hehe);
    }

    private onDecorate(evt:egret.TouchEvent){
        this.showType(Model.DEC_BG);
        this.img_cur_mark.x = this.img_decorate.x + 17;
        this.img_cur_mark.y = this.img_decorate.y + 55;
    }
    private onDecNest(evt:egret.TouchEvent){
        this.showType(Model.DEC_NEST);
        this.img_cur_mark.x = this.img_dec_nest.x + 17;
        this.img_cur_mark.y = this.img_dec_nest.y + 55;
    }
    private onDecDoll(evt:egret.TouchEvent){
        this.showType(Model.DEC_TOY);
        this.img_cur_mark.x = this.img_dec_doll.x + 17;
        this.img_cur_mark.y = this.img_dec_doll.y + 55;
    }
    private onDecFrame(evt:egret.TouchEvent){
        this.showType(Model.DEC_FRAME);
        this.img_cur_mark.x = this.img_dec_frame.x + 17;
        this.img_cur_mark.y = this.img_dec_frame.y + 55;
    }
    private onDecGlass(evt:egret.TouchEvent){
        this.showType(Model.DEC_GLASS);
        this.img_cur_mark.x = this.img_glass.x + 17;
        this.img_cur_mark.y = this.img_glass.y + 55;
    }
    private onDecHat(evt:egret.TouchEvent){
        this.showType(Model.DEC_HAT);
        this.img_cur_mark.x = this.img_hat.x + 17;
        this.img_cur_mark.y = this.img_hat.y + 55;
    }
    private onDecNeck(evt:egret.TouchEvent){
        this.showType(Model.DEC_NECKLACE);
        this.img_cur_mark.x = this.img_necklace.x + 17;
        this.img_cur_mark.y = this.img_necklace.y + 55;
    }
    private onSave(evt:egret.TouchEvent){
        var len = this.tempDressData.length;
        if( len == 0) return;
        var buyObj = [];
        var dressObj = {};
        var id;
        var good;
        var hasDress;
        var unlocks:string[]=[];
        for(var i = 0; i < len; i++){
            id = this.tempDressData[i];
            good = Model.GetDecorateById(id);
            if( Model.HasFreeDec(id)){
                dressObj[good.classify] = id;
                hasDress = true;
            }else{
                var unlockConfig = Model.GetDecUnlockConfig(id);
                if( unlockConfig ){
                    if( unlockConfig.type == 1){
                        if( Model.me.vipLevel < unlockConfig.count){
                            unlocks.push(good.name);
                            continue;
                        }
                    }
                }
                if( good.canBuy ) {
                    buyObj.push(id);
                }
            }
        }
        if( unlocks.length != 0){
            ShowHint(unlocks.join(",")+"未解锁");
        }
        if( hasDress)
            window["__dressup"](this.curPet.petId,JSON.stringify(dressObj));
        if( buyObj.length)
            DecorateBuyPanel.getInstance().show(buyObj);
        Model.checkGuide("button_save");
    }
    private onBuy(evt:egret.TouchEvent){
        var unlockConfig = Model.GetDecUnlockConfig(this.curGood.id);
        if( unlockConfig ){
            if( unlockConfig.type == 1){
                if( Model.me.vipLevel < unlockConfig.count){
                    ShowHint("解锁条件不够");
                    return;
                }
            }
        }
        if( this.curGood.byDiamond){
            if( Model.me.diamond < this.curGood.disPrice){
                BuyDiamondPanel.getInstance().show();
            }else{
                RemindPanel.getInstance().showContent("是否花费"+this.curGood.disPrice+"钻石购买"+this.curGood.name,this,this.okBuy);
            }
        }else if(this.curGood.bySproutPoint ){
            if( Model.me.sproutPoint < this.curGood.disPrice){
                ShowHint("萌点不足");
            }else{
                RemindPanel.getInstance().showContent("是否花费"+this.curGood.disPrice+"萌点购买"+this.curGood.name,this,this.okBuy);
            }
        }else{
            if(this.curPet.type == Model.GOOD_TYPE_CAT){
                var hair = Model.me.catHair;
            }else{
                hair = Model.me.dogHair;
            }
            if( hair < this.curGood.disPrice){
                ShowHint("毛发不足");
            }else{
                RemindPanel.getInstance().showContent("是否花费"+this.curGood.hair+"毛发购买"+this.curGood.name,this,this.okBuy);
            }
        }
    }
    private okBuy(){
        window["__buydecorates"](PetMgr.getInstance().curPet.petId,JSON.stringify([this.curGood.id]),0);
    }
    private onReset(evt:egret.TouchEvent){
        this.tempDressData = [];
        this.updateItems();
        this.updateButtons();
    }
    private onTry(evt:egret.TouchEvent){
        this.doDress();
        this.updateButtons();
        this.indexMap[this.curGood.classify] = this.curIndex;
        Model.checkGuide("try");
    }
    private onDressup(evt:egret.TouchEvent){
        this.doDress();
        this.updateButtons();
        this.indexMap[this.curGood.classify] = this.curIndex;
    }
    private getIndex():number{
        var len = this.tempDressData.length;
        var decId;
        var good;
        for(var i = 0; i < len; i++){
            decId = this.tempDressData[i];
            good = Model.GetDecorateById(decId);
            if( good.classify == this.curGood.classify){
                return i;
            }
        }
        return -1;
    }
    private getAnotherIndex():number{
        var len = this.limitTryData.length;
        var decId;
        var good;
        for(var i = 0; i < len; i++){
            decId = this.limitTryData[i];
            good = Model.GetDecorateById(decId);
            if( good.classify == this.curGood.classify){
                return i;
            }
        }
        return -1;
    }
    private getOriginal(classify:number = 0){
        var len = this.curPetDecorates.length;
        var dec:DecorateInfo;
        if( classify == 0)
            classify = this.curGood.classify;
        for( var i = 0 ; i < len; i++){
            dec = this.curPetDecorates[i];
            if( dec.classify == classify && dec.petId == this.curPet.petId){
                return dec.goodsId;
            }
        }
        return 0;
    }
    private onTakeoff(evt:egret.TouchEvent){
        this.takeoff(this.curGood.id);
    }
    public takeoff(did){
        var idx = this.tempDressData.indexOf(did);
        if( idx != -1){
            this.tempDressData.splice(idx, 1);
            this.takeoffAll();
            this.updateButtons();
        }else if(this.limitTryData.indexOf(did) != -1){
            this.limitTryData.splice(idx, 1);
            this.takeoffAll();
            this.updateButtons();
        }else{
            var id = this.getOriginal();
            var good:GoodInfo = Model.GetDecorateById(id);
            if( id == did){
                //this.takeOffData.push(good.classify);
                var key = good.classify;
                var obj = {};
                obj[key] = 0;
                window["__dressup"](this.curPet.petId,JSON.stringify(obj));
            }
        }
    }

    private onRight(evt:egret.TouchEvent){
        this.curIndex++;
        if( this.curIndex >= this.curItems.length){
            this.curIndex = this.curItems.length - 1;
        }
        else{
            this.updateDisplay();
        }
    }

    private onLeft(evt:egret.TouchEvent){
        this.curIndex--;
        if( this.curIndex < 0){
            this.curIndex = 0;
        }
        else{
            this.updateDisplay();
        }
    }

    public updateItems(){
        var type = this.getOriginal(Model.DEC_BG);
        PetMgr.getInstance().changeBg(type);

        type = this.getOriginal(Model.DEC_NEST);
        this.img_nest.visible = type != 0;
        if( type != 0)
            this.img_nest.source = GameConst.Res_Root+"resource/assets/decorates/"+type+ ".png";

        type = this.getOriginal(Model.DEC_TOY);
        this.img_doll.visible = type != 0;
        if( type != 0)
            this.img_doll.source = GameConst.Res_Root+"resource/assets/decorates/"+type+ ".png";

        type = this.getOriginal(Model.DEC_FRAME);
        this.img_head.visible = this.img_frame.visible = type != 0;
        if( type != 0)
            this.img_frame.source = GameConst.Res_Root+"resource/assets/decorates/"+type+ ".png";

        type = this.getOriginal(Model.DEC_HAT);
        if( type != 0)
            RES.getResByUrl(GameConst.Res_Root+"resource/assets/decorates/"+type+ ".png",this.onHatComplete,this);
        else
            AnimationController.getInstance().setSlotDisplay("mypet","tou",false);

        type = this.getOriginal(Model.DEC_NECKLACE);
        if( type != 0)
            RES.getResByUrl(GameConst.Res_Root+"resource/assets/decorates/"+type+ ".png",this.onNeckComplete,this);
        else
            AnimationController.getInstance().setSlotDisplay("mypet","bozi",false);

        type = this.getOriginal(Model.DEC_GLASS);
        if( type != 0)
            RES.getResByUrl(GameConst.Res_Root+"resource/assets/decorates/"+type+ ".png",this.onGlassComplete,this);
        else
            AnimationController.getInstance().setSlotDisplay("mypet","yanjing",false);
    }

    public onDressBack(){
        var len = this.tempDressData.length;
        var did;
        for(var i = len-1; i >= 0 ; i--){
            did = this.tempDressData[i];
            if( Model.DecorateOn(did)){
                this.tempDressData.splice(i,1);//如果是脱下的话需要另外处理
            }
        }
        this.updateDisplay();
        this.updateItems();
    }

    public onBuyBack(flag:number=0){
        this.updateDisplay();
        if( flag == 1){
            this.tempDressData = [];
        }
    }
   
    private addedToStage(evt:egret.Event){
        this.img_decorate.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onDecorate, this);
        this.img_dec_nest.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onDecNest, this);
        this.img_dec_doll.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onDecDoll, this);
        this.img_dec_frame.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onDecFrame, this);
        this.img_glass.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onDecGlass, this);
        this.img_hat.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onDecHat, this);
        this.img_necklace.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onDecNeck, this);
        this.img_left.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onLeft, this);
        this.img_right.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onRight, this);
        this.img_reset.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onReset, this);
        this.img_buy.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBuy, this);
        this.img_save.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onSave, this);
        this.img_takeoff.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTakeoff, this);
        this.img_dressup.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onDressup, this);
        this.img_try.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTry, this);
        this.updatePetPage();
    }
    private removedFromStage(evt:egret.Event){
        this.img_decorate.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onDecorate, this);
        this.img_dec_nest.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onDecNest, this);
        this.img_dec_doll.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onDecDoll, this);
        this.img_dec_frame.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onDecFrame, this);
        this.img_glass.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onDecGlass, this);
        this.img_hat.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onDecHat, this);
        this.img_necklace.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onDecNeck, this);
        this.img_left.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onLeft, this);
        this.img_right.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onRight, this);
        this.img_reset.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onReset, this);
        this.img_buy.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onBuy, this);
        this.img_save.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onSave, this);
        this.img_takeoff.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTakeoff, this);
        this.img_dressup.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onDressup, this);
        this.img_try.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTry, this);
    }
    public img_guild_logo:eui.Image;
    public img_frame:eui.Image;
    public img_doll:eui.Image;
    public img_nest:eui.Image;
    public img_dec_doll:eui.Image;
    public img_glass:eui.Image;
    public img_hat:eui.Image;
    public img_decorate:eui.Image;
    public img_dec_nest:eui.Image;
    public img_dec_frame:eui.Image;
    public img_necklace:eui.Image;
    public img_left:eui.Image;
    public img_right:eui.Image;
    public img_goods_bg:eui.Image;
    public lab_good_name:eui.Label;
    public img_money:eui.Image;
    public group_price:eui.BitmapLabel;
    public lab_desc_1:eui.Label;
    public lab_desc_2:eui.Label;
    public img_icon:eui.Image;
    public img_using:eui.Image;
    public img_reset:eui.Image;
    public img_buy:eui.Image;
    public img_save:eui.Image;
    public img_try:eui.Image;
    public img_takeoff:eui.Image;
    public img_dressup:eui.Image;
    public img_cur_mark:eui.Image;
    public img_using_icon:eui.Image;
    public img_head:eui.Image;
    public lab_dec_desc:eui.Label;
    public partAdded(name:string, instance:any){
        super.partAdded(name, instance);
        if( name == "img_frame"){
            this.img_frame = instance;
        }else if( name == "img_guild_logo"){
            this.img_guild_logo = instance;
        }else if( name == "img_doll"){
            this.img_doll = instance;
        }else if( name == "lab_dec_desc"){
            this.lab_dec_desc = instance;
        }else if( name == "img_nest"){
            this.img_nest = instance;
        }else if( name == "img_dec_doll"){
            this.img_dec_doll = instance;
        }else if( name == "img_glass"){
            this.img_glass = instance;
        }else if( name == "img_hat"){
            this.img_hat = instance;
        } else if( name == "img_decorate"){
            this.img_decorate = instance;
        }else if( name == "img_dec_nest"){
            this.img_dec_nest = instance;
        }else if( name == "img_dec_frame"){
            this.img_dec_frame = instance;
        }else if( name == "img_necklace"){
            this.img_necklace = instance;
        }else if( name == "img_left"){
            this.img_left = instance;
        }else if( name == "img_right"){
            this.img_right = instance;
        }else if( name == "img_goods_bg"){
            this.img_goods_bg = instance;
        } else if( name == "img_money"){
            this.img_money = instance;
        }else if( name == "group_price"){
            this.group_price = instance;
        }else if( name == "lab_desc_1"){
            this.lab_desc_1 = instance;
        }else if( name == "lab_desc_2"){
            this.lab_desc_2 = instance;
        }else if( name == "img_icon"){
            this.img_icon = instance;
        }else if( name == "img_using"){
            this.img_using = instance;
        }else if( name == "img_reset"){
            this.img_reset = instance;
        }else if( name == "img_buy"){
            this.img_buy = instance;
        }else if( name == "img_save"){
            this.img_save = instance;
        }else if( name == "img_dressup"){
            this.img_dressup = instance;
        }else if( name == "img_takeoff"){
            this.img_takeoff = instance;
        }else if( name == "img_try"){
            this.img_try = instance;
        }else if( name == "img_cur_mark"){
            this.img_cur_mark = instance;
        }else if( name == "img_using_icon"){
            this.img_using_icon = instance;
        }else if( name == "img_head"){
            this.img_head = instance;
            //this.img_head.source = Model.me.figureurl;
            if( Model.me.platform != PlatformEnum.QQBROWSER){
                this.img_head.source = Model.me.figureurl;
            }else{
                this.img_head.source = RES.getRes("default_head_"+(Model.me.id%5));
            }
        }
    }
    private static _instance:DecorateScene;
    public static getInstance():DecorateScene{
        if( DecorateScene._instance == null )
            DecorateScene._instance = new DecorateScene();
        return DecorateScene._instance;
    }
}